if exists (select * from dbo.sysobjects where id = object_id(N'dbo.InsertSourceTable') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure dbo.InsertSourceTable

go


CREATE PROCEDURE dbo.InsertSourceTable
	@TableName VARCHAR(128),
	@TableId INT OUTPUT
AS

SET @TableId = -1
SELECT @TableId=ID FROM  dbo.SourceTable WHERE Name=@TableName

IF @TableId=-1
BEGIN
	INSERT INTO dbo.SourceTable (Name) VALUES (@TableName)
	SET @TableId = scope_identity()
END



